/* 
 * 合作机构成员集合。
 */
Ext.define("ES.store.CooperationMemberStore",{
    extend:"Ext.data.Store",
    model:"ES.model.CooperationMemberModel",
    pageSize:20,
    autoLoad:false,
    remoteSort:true,
    proxy:{
            type:"ajax",
            url:"CooperationMembers!list.action",
            reader:{
                type:"json",
                root:"dataSource.entityList",
                totalProperty:"dataSource.totalCounts"
            },
            listeners:{
                exception:function(proxy, resp, operation, opt){
                    Ext.MessageBox.show({
                        title:"远程异常",
                        msg:operation.getError(),
                        icon:Ext.MessageBox.ERROR,
                        buttons:Ext.Msg.OK
                    });
                }
            }
    },
    listeners:{
        beforeload:function(store, operation){
            Ext.getBody().mask("正在加载数据，请稍后...");
            Ext.apply(store.proxy.extraParams,{
                ascProperty:"MemberCode",
                asc:true
            });
        },
        load:function(){
            Ext.getBody().unmask();
        },
        update:function(store, record){
            if(record != null && record.get("cooperationID") != "" && record.get("memberCode") != ""){
                var currPage = store.currentPage;
                Ext.Ajax.request({
                    url:"CooperationMembersEdit!update.action",
                    params:{
                        cooperationID:record.get("cooperationID"),
                        memberID:record.get("memberID"),
                        memberCode:record.get("memberCode"),
                        memberName:record.get("memberName"),
                        telPhone:record.get("telPhone"),
                        QQ:record.get("QQ"),
                        MSN:record.get("MSN"),
                        emailAddress:record.get("emailAddress")
                    },
                    method:"POST",
                    success:function(){
                        store.removeAll();
                        store.loadPage(currPage);
                    }
                });
            }
        },
        remove:function(store, record){
            if(record != null && record.get("memberID") != "" && record.get("cooperationID") != ""){
                var currPage = store.currentPage;
                Ext.Ajax.request({
                    url:"CooperationMembersEdit!delete.action",
                    params:{
                        memberID:record.get("memberID")
                    },
                    method:"POST",
                    success:function(){
                        store.removeAll();
                        store.loadPage(currPage);
                    }
                });
            }
        }
    }
})